<!-- 简历查询 -->

<script>
import HPCommonPage from "@/components/HPCommonPage";
import HPTable from "@/components/HPTable";
import { resumeSearchTableColumn } from "./../js/cloumn";
import { resumeSearchStatus } from "../js/status";
import getQuery from '@/utils/mixins/getQuery';

function fetchSelectResumeLists(store, opts) {
  return store.dispatch("FETCH_SELECT_RESUMES", opts);
}
export default {
  mixins: [getQuery],
  created() {
    this.loadTableLists();
  },
  methods: {
    // * 获取table数据
    async loadTableLists() {
      this.isLoad = true;
      await fetchSelectResumeLists(this.$store, {
        ...this.selectData,
      });
      this.isLoad = false;
      let { state, data } = this.$store.getters.getSelectResumeLists;
      if (state === "0000") {
        this.totals = data.total;
        this.tableData = data.list;
        const { lastPage, pageNum } = data
        if(pageNum > lastPage && lastPage > 0) {
          this.selectData.pageCurrent = lastPage
          this.loadTableLists()
        }
      }
    },
    // * 查询
    onSearch() {
      this.selectData.pageCurrent = 1;
      this.searchData = { ...this.selectData }
      this.loadTableLists();
    },
    // * 查看
    onLookDetail({ needsCvId, is_selected }) {
      this.$router.push({
        path: `/selectres/detail/${needsCvId}`,
        query: {
          stus: `${is_selected}`,
          formQuery: JSON.stringify(this.searchData),
        },
      });
    },
    // * 切换页条数
    handleSizeChange(val) {
      this.selectData.pageSize = val;
      this.selectData.pageCurrent = 1;
      this.searchData = { ...this.selectData }
      this.loadTableLists();
    },
    // * 切换页数
    handleCurrentChange(val) {
      this.selectData.pageCurrent = val;
      this.searchData = { ...this.selectData }
      this.loadTableLists();
    },
  },
  data() {
    return {
      selectData: {
        // * 查询条件对象
        needsCode: "",
        postCode: "",
        name: "",
        isselected: "",
        pageCurrent: 1,
        pageSize: 10,
      },
      stateOptions: resumeSearchStatus,
      tableHeaderItems: resumeSearchTableColumn, // * table字段
      tableData: [], // * table数据
      isLoad: false, // * 加载动画开关
      totals: 0, // * 总条数
    };
  },
  components: {
    HPCommonPage,
    HPTable,
  },
};
</script>

<template>
  <HPCommonPage :titleText="'简历筛选 / 简历查询'">
    <template v-slot:searchForm>
      <el-form :inline="true" :model="selectData" class="form-box res-form-box">
        <el-form-item label="需求单号：">
          <el-input
            v-model="selectData.needsCode"
            clearable
            placeholder="请输入需求单号"
          ></el-input>
        </el-form-item>
        <el-form-item label="岗位名称：">
          <el-input
            v-model="selectData.postCode"
            clearable
            placeholder="请输入岗位名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="姓名：">
          <el-input
            v-model="selectData.name"
            clearable
            placeholder="请输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态：">
          <el-select
            v-model="selectData.isselected"
            placeholder="请选择状态"
            clearable=""
          >
            <el-option
              v-for="item in stateOptions"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </template>
    <template v-slot:searchFormbtn>
      <el-button type="success" size="small" @click="onSearch">查询</el-button>
    </template>
    <template v-slot:table>
      <HPTable
        :tableHeaderItems="tableHeaderItems"
        :tableData="tableData"
        :loading="isLoad"
      >
      </HPTable>
    </template>
    <template v-slot:pagination>
      <el-pagination
        v-if="totals"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="selectData.pageCurrent"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="selectData.pageSize"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="totals"
      >
      </el-pagination>
    </template>
  </HPCommonPage>
</template>
